package com.hx.demo.serialize;

import com.hx.demo.User;

/**
 * @author Huathy
 * @date 2021-10-14 23:38
 * @description
 */
public class TestSerilize {
    public static void main(String[] args) {
        User user = new User("Huathy",18);
        // ===== 原生序列化 =====
//        ISerializer serializer = new JavaSerializer();
//        serializer.serialize(user);
//        User deuser = serializer.deserialize(null,User.class);
//        System.out.println(deuser);

        // ===== 文件序列化 =====
//        ISerializer serializer = new JavaSerializerWithStore();
//        serializer.serialize(user);
//        User deuser = serializer.deserialize(null,User.class);
//        System.out.println(deuser);

        //===== xml序列化 =====
//        ISerializer serializer = new XStreamSerializer();
//        byte[] bytes = serializer.serialize(user);
//        System.out.println(bytes.length);
//        System.out.println(new String(bytes));
//        User res = serializer.deserialize(bytes,null);
//        System.out.println(res);

//        // ===== fastjson序列化 =====
//        ISerializer serializer = new FastJsonSerializer();
//        byte[] bytes = serializer.serialize(user);
//        System.out.println(bytes.length);
//        System.out.println(new String(bytes));
//        User res = serializer.deserialize(bytes,User.class);
//        System.out.println(res);

//        // ===== hessian序列化 =====
        ISerializer serializer = new HessianSerializer();
        byte[] bytes = serializer.serialize(user);
        System.out.println(bytes.length);
        System.out.println(new String(bytes));
        User res = serializer.deserialize(bytes,User.class);
        System.out.println(res);


    }
}
